// 将4-path&file-test的项目放在本地服务器中运行

// Introuuction module
const http = require("http");
const fs = require("fs");
const path = require("path");

// Bulid server
const server = http.createServer();

server.on("request", (req, res) => {
  const url = req.url;
  let fPath = "";
  if (url === "/") {
    fPath = path.join(__dirname, "./4-path&file-test/index.html");
  } else {
    fPath = path.join(__dirname, "./4-path&file-test", url);
  }
  fs.readFile(fPath, "utf8", (err, dataStr) => {
    if (err) return res.end("404 NOT FOUND");
    res.end(dataStr);
  });
});
server.listen(8080, () => {
  console.log("server running at http://127.0.0.1:8080");
});
